package com.phonemap;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.datastore.Entity;
import com.phonemap.common.Util;
import com.phonemap.models.Position;

@SuppressWarnings("serial")
public class IndexServlet extends BaseServlet{
	private static final Logger logger = Logger.getLogger(PositionServlet.class
			.getCanonicalName());
	
	/**
	 * Get the requested position entities in JSON format
	 */
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		super.doGet(req, resp);
		logger.log(Level.INFO, "Obtaining Position listing");
		String phone = req.getParameter("phone");
		PrintWriter out = resp.getWriter();
		Iterable<Entity> entities = null;
		entities = Position.getRelatedPhonePosstions(phone);
		out.println(Util.writeJSON(entities, "User"));
		
		return;
	}
	
	/**
	 * Insert the new position
	 */
	protected void doPut(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
	}
	
	/**
	 * Redirect the call to doDelete or doPut method
	 */
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
	}

}
